/**
 * @file pcm_to_wav.h
 * @author haier Max (shangbaorun@haier.com)
 * @brief 
 * @version 0.1
 * @date 2022-02-21
 * 
 * @copyright Copyright (c) 2022
 * 
 */
#ifndef __PCM_TO_WAV_H__
#define __PCM_TO_WAV_H__

#define ID_RIFF 0x46464952
#define ID_WAVE 0x45564157
#define ID_FMT  0x20746d66
#define ID_DATA 0x61746164

#define FORMAT_PCM 1

/** Audio sample format of a PCM.
 * The first letter specifiers whether the sample is signed or unsigned.
 * The letter 'S' means signed. The letter 'U' means unsigned.
 * The following number is the amount of bits that the sample occupies in memory.
 * Following the underscore, specifiers whether the sample is big endian or little endian.
 * The letters 'LE' mean little endian.
 * The letters 'BE' mean big endian.
 * This enumeration is used in the @ref pcm_config structure.
 * @ingroup libtinyalsa-pcm
 */
enum pcm_format_haier {

/* Note: This section must stay in the same
 * order for binary compatibility with older
 * versions of TinyALSA. */

    HAIER_PCM_FORMAT_INVALID = -1,
    /** Signed 16-bit, little endian */
    HAIER_PCM_FORMAT_S16_LE = 0,
    /** Signed, 32-bit, little endian */
    HAIER_PCM_FORMAT_S32_LE,
    /** Signed, 8-bit */
    HAIER_PCM_FORMAT_S8,
    /** Signed, 24-bit (32-bit in memory), little endian */
    HAIER_PCM_FORMAT_S24_LE,
    /** Signed, 24-bit, little endian */
    HAIER_PCM_FORMAT_S24_3LE,

/* End of compatibility section. */

    /** Signed, 16-bit, big endian */
    HAIER_PCM_FORMAT_S16_BE,
    /** Signed, 24-bit (32-bit in memory), big endian */
    HAIER_PCM_FORMAT_S24_BE,
    /** Signed, 24-bit, big endian */
    HAIER_PCM_FORMAT_S24_3BE,
    /** Signed, 32-bit, big endian */
    HAIER_PCM_FORMAT_S32_BE,
    /** 32-bit float, little endian */
    HAIER_PCM_FORMAT_FLOAT_LE,
    /** 32-bit float, big endian */
    HAIER_PCM_FORMAT_FLOAT_BE,
    /** Max of the enumeration list, not an actual format. */
    HAIER_PCM_FORMAT_MAX
};

unsigned int haier_pcm_format_to_bits(enum pcm_format_haier format);
unsigned int get_file_size(char * file_name);
int pcm_translate_to_wav(char *pcm_file,char *wav_file,int channel,int rate);
int wav_translate_to_pcm(char * wav_file,char *pcm_file);

int pcm_split_2_channels(char *pcm_files);
int get_pcm_data_by_channel_num(char *file_name,int channel_num,int max_channel_num,int len,short *data);
int save_data_to_file(char *file_name , short *data,int len);
#endif